# This Python file uses the following encoding: utf-8
# -*- coding: utf-8 -*-
import re
import sys
import time
import datetime
import logging
import json
import copy
from elasticsearch import Elasticsearch

# 10.15.212.31  online
# 10.10.12.92 操作日志线上
# logOnline='10.10.12.92'

reload(sys)
sys.setdefaultencoding('utf8')

readingOnline = '10.15.212.31'
es = Elasticsearch(hosts=readingOnline)

# es find u'中文' 发
index_name_book = "index_id_book_1445234770866_20151019140610882"
index_name_author="index_id_author_1461311103055_20160422154503070"
index_type_book = "book"
index_type_volume = "volume"
index_type_chapter = "chapter"
index_type_author = "author"
index_type_log = "videooperateinfo";
# esRet=es.get(index=index_name, doc_type=index_type_book, id=7505661)['_source']
# print(json.dumps(esRet))
index_name = "_all";

def ddl():
    es.indices.create(index='my-index', ignore=400)
    None;

def dml(action,index,doc_type,id,body):
    '''

    :param action: 0 增加 1删除  2更新
    :param index:
    :param doc_type:
    :param id:
    :param body:
    :return:
    '''
    if action==0:
        es.index(index=index, doc_type=doc_type,body=body,id=id )
    elif action==1:
        es.delete(index,doc_type,id)
    elif action==2:
        es.update(index=index,doc_type=doc_type,id=id,body=body)



data = {
    "id": 200000090,
    "validStatus": 1,
    "uid": 155881320,
    "createTime":"2016-08-13 12:36:29",
    "mobilePhone": "13381224550",
    "email": "",
    "systemCode": 1,
    "isSignBook": 0,
    "name": "测试作者",
    "realName": "测试作者",
    "qipuId": 200112050,
    "qq": ""
}

dml(0,index_name_author,index_type_author,200000090,data)




    # print(json.dumps(indexSearch(index_type_chapter,size=10,dsl=dslfilterChapter),indent=4))
